fix: fixed issue where git may not be setup on users computer.#23
fix: fixed issue where git may not be setup on users computer.#23dlabaj merged 2 commits intopatternfly:mainfrom
Conversation
|
Caution Review failedPull request was closed or merged during review WalkthroughAdds a new --git-init CLI option and a prompt-and-set flow for local Git user.identity, a new git-user-config module and tests, updates to GitHub setup/error messaging, and minor test and comment adjustments. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI as CLI (init)
participant GitInit as Git (git init / .git)
participant Config as promptAndSetLocalGitUser
participant Inquirer as inquirer
participant Git as execa (git config)
participant GH as offerAndCreateGitHubRepo
User->>CLI: Run init (with --git-init)
CLI->>GitInit: Ensure .git exists (git init if missing)
CLI->>Config: Call promptAndSetLocalGitUser(cwd)
Config->>Git: git config --global user.name
Git-->>Config: global name (or empty)
Config->>Git: git config --global user.email
Git-->>Config: global email (or empty)
Config->>Inquirer: Prompt userName (default global)
Inquirer-->>Config: user input (trim)
Config->>Inquirer: Prompt userEmail (default global)
Inquirer-->>Config: user input (trim)
alt both non-empty
Config->>Git: git config --local user.name (cwd, stdio: inherit)
Git-->>Config: success
Config->>Git: git config --local user.email (cwd, stdio: inherit)
Git-->>Config: success
Config->>CLI: Log success
else missing/empty
Config->>CLI: Log validation error (no local config)
end
CLI->>GH: Continue with offerAndCreateGitHubRepo(cwd)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
src/cli.ts (1)
47-58: Wrapinitaction in error handling for consistent CLI failure behavior.Line 47–58 can throw from
git init, prompt flow, or GitHub setup and currently bubbles raw errors. Consider aligning with the other commands’process.exit(1)handling.Proposed refactor
- .action(async (dirPath, options) => { - const cwd = dirPath ? path.resolve(dirPath) : process.cwd(); - const gitDir = path.join(cwd, '.git'); - if (!(await fs.pathExists(gitDir))) { - await execa('git', ['init'], { stdio: 'inherit', cwd }); - console.log('✅ Git repository initialized.\n'); - } - if (options.gitInit) { - await promptAndSetLocalGitUser(cwd); - } - await offerAndCreateGitHubRepo(cwd); - }); + .action(async (dirPath, options) => { + try { + const cwd = dirPath ? path.resolve(dirPath) : process.cwd(); + const gitDir = path.join(cwd, '.git'); + if (!(await fs.pathExists(gitDir))) { + await execa('git', ['init'], { stdio: 'inherit', cwd }); + console.log('✅ Git repository initialized.\n'); + } + if (options.gitInit) { + await promptAndSetLocalGitUser(cwd); + } + await offerAndCreateGitHubRepo(cwd); + } catch { + process.exit(1); + } + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/cli.ts` around lines 47 - 58, The action handler passed to .action (the async function that runs git init, promptAndSetLocalGitUser, and offerAndCreateGitHubRepo) should be wrapped in a try/catch so any error (from execa('git', ['init'], ...), promptAndSetLocalGitUser, or offerAndCreateGitHubRepo) is caught and handled consistently; catch the error, log a clear message plus the error details (e.g., console.error or the existing logger), and call process.exit(1) to mirror other commands' failure behavior. Ensure you reference the same async .action handler, keep awaited calls inside the try block, and rethrow/exit only inside the catch.src/__tests__/git-user-config.test.ts (1)
73-77: Strengthen the “skip local config” assertion.The current check only guards one call shape. Prefer asserting no
git config --local ...invocations at all to fully protect this branch.Proposed test tightening
- expect(mockExeca).not.toHaveBeenCalledWith( - 'git', - ['config', '--local', 'user.name', expect.any(String)], - expect.any(Object), - ); + const localConfigCalls = mockExeca.mock.calls.filter( + ([cmd, args]) => cmd === 'git' && Array.isArray(args) && args[0] === 'config' && args[1] === '--local' + ); + expect(localConfigCalls).toHaveLength(0);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/__tests__/git-user-config.test.ts` around lines 73 - 77, The test currently only forbids one specific call shape to mockExeca; instead ensure no invocation of git config with the --local flag occurs by scanning mockExeca.mock.calls and asserting none match (where call[0] === 'git' and call[1] includes '--local'). Replace the expect.not.toHaveBeenCalledWith(...) line with a check that iterates mockExeca.mock.calls (or uses Array.prototype.some) and expects the predicate (git + args.includes('--local')) to be false so any git config --local invocation is caught; reference mockExeca in your change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/github.ts`:
- Around line 95-96: The docstring for createRepo is incorrect: it says "Does
not push" but the implementation calls gh repo create with the --push flag;
update the comment for the createRepo function to reflect that it does push the
repository (or remove the "Does not push" clause) so the documentation matches
the behavior of the gh repo create invocation.
- Around line 64-75: The catch block around the execa('git', ['commit'...]) call
currently swallows all errors and always throws a generic "set your git
identity" message; change the catch to capture the thrown error (e.g., catch
(err)), inspect err.stderr/err.message for identity-related patterns like
"user.email", "user.name", "author identity", or "unable to auto-detect email",
and only replace with the identity-help message when those patterns match;
otherwise rethrow the original error or throw a new Error that includes the
original error message/stack so real commit failures (hooks, permissions, index
state, etc.) are preserved. Ensure you reference the execa invocation and
projectPath when updating the try-catch so the behavior is limited to identity
detection rather than blanket replacement.
- Line 90: The console.log message contains grammar and typo errors; update the
string passed to console.log (the log that starts with " • Your user name...")
to correct wording — e.g. change "my not be set" to "may not be set", fix "the
your `user.name`" to "your `user.name`", and change "try to again" to "try
again" so the guidance reads clearly and grammatically when printed by
console.log in src/github.ts.
---
Nitpick comments:
In `@src/__tests__/git-user-config.test.ts`:
- Around line 73-77: The test currently only forbids one specific call shape to
mockExeca; instead ensure no invocation of git config with the --local flag
occurs by scanning mockExeca.mock.calls and asserting none match (where call[0]
=== 'git' and call[1] includes '--local'). Replace the
expect.not.toHaveBeenCalledWith(...) line with a check that iterates
mockExeca.mock.calls (or uses Array.prototype.some) and expects the predicate
(git + args.includes('--local')) to be false so any git config --local
invocation is caught; reference mockExeca in your change.
In `@src/cli.ts`:
- Around line 47-58: The action handler passed to .action (the async function
that runs git init, promptAndSetLocalGitUser, and offerAndCreateGitHubRepo)
should be wrapped in a try/catch so any error (from execa('git', ['init'], ...),
promptAndSetLocalGitUser, or offerAndCreateGitHubRepo) is caught and handled
consistently; catch the error, log a clear message plus the error details (e.g.,
console.error or the existing logger), and call process.exit(1) to mirror other
commands' failure behavior. Ensure you reference the same async .action handler,
keep awaited calls inside the try block, and rethrow/exit only inside the catch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 389233c2-9807-4053-9cc8-331454ccd62a
📒 Files selected for processing (6)
src/__tests__/create.test.tssrc/__tests__/git-user-config.test.tssrc/cli.tssrc/create.tssrc/git-user-config.tssrc/github.ts
|
🎉 This PR is included in version 1.2.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fix an issue were git username and email are not set on their computer.
Summary by CodeRabbit
New Features
Bug Fixes
Tests